﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;
using System.IO;
using InnovTech.Util.IO;

namespace InnovTech.Util.Crypto
{
    public abstract class StreamCryptor
    {
        public abstract SymmetricAlgorithm Algo { get; }

        public MemoryStream Encrypt(object obj)
        {
            return CryptoUtil.Encrypt(obj, Algo.CreateEncryptor());
        }

        public object Decrypt(Stream stream)
        {
            long origin = StreamUtil.Reset(stream);
            object obj = CryptoUtil.Decrypt(stream, Algo.CreateDecryptor());
            StreamUtil.Seek(stream, origin);
            return obj;
        }
    }
}
